using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using TestProject1.DependencyInjection;
using UnitTest.Model;
using UnitTest.Service;
using UnitTestDemo.Controller;

namespace TestProject1.Controller_Test;

public class ValueTest_Should
{
    Mock<IStudentService> mockStudentSev = new Mock<IStudentService>();
    private StudentController _studentController;

    private IStudentService _studentService;
    private DI_Test _diTest = new DI_Test();

    public ValueTest_Should()
    {
      //  mockStudentSev.Setup(r => r.GetList());

        var container = _diTest.DICollections();
        _studentService = container.Services.GetService<IStudentService>();
        _studentController = new StudentController(_studentService);
        _studentController._studentService = _studentService;

    }

    
    [Fact]
    public async void Get_Student_One_Test()
    {
        var res = await _studentController.Get(1);

        // 如果res为空 测试失败
        // 如果res不为空 测试成功
        Assert.NotNull(res);
    }

    [Fact]
    public async void Get_Student_All_Test()
    {
        var res = await _studentController.GetAllStudent();
        Assert.NotNull(res);

    }

    [Fact]
    public async void Add_Student_Test()
    {
        Student stu=new Student()
        {
            ID = 5,
            Name = "测试1",
            Age = 20,
            Gender = "男",
            Status =1

            
        };
        var res = await _studentService.Post(stu);
        Console.WriteLine(res);
        Assert.Equal(res,1);

    }
    
    [Fact]
    public async void Del_Student_One_Test()
    {
        var res = await _studentController.Delete(4);
        Assert.NotNull(res);

    }

}